const { ccclass, property } = cc._decorator;

import { app } from '../../../app/app';
import { menu } from '../../../app/decorator';
import { viewNamesEnum } from '../../../app/executor';
import BaseButtonTouch from './base/BaseButtonTouch';

@ccclass
@menu(__filename, '触摸展示')
export default class TouchShow extends BaseButtonTouch {
    @property
    _uiName: string = viewNamesEnum[0] || '';
    @property({
        type: cc.Enum(viewNamesEnum)
    })
    get uiName(): number {
        const num = this._uiName ? viewNamesEnum[this._uiName] : 0;
        return typeof num === 'undefined' ? -1 : num;
    }
    set uiName(value) {
        this._uiName = viewNamesEnum[value];
    }

    @property
    customData: boolean = false;
    @property({
        visible(this: TouchShow) {
            return this.customData;
        }
    })
    data: string = '';

    onLoad() {
        this.target.on(this.timeEvent, function () {
            viewNamesEnum[this.uiName] && app.manager.ui.show({
                name: viewNamesEnum[this.uiName] as any,
                data: this.customData ? { type: 'clickShow', data: this.data } : undefined
            });
        }, this);
    }
}
